package linklist;

public class Test {
    public static void main(String[] args) {
        MySingleList mySingleList = new MySingleList();
        mySingleList.addFirst(1);
        mySingleList.addFirst(3);
        mySingleList.addFirst(5);
        mySingleList.addFirst(3);
        mySingleList.addFirst(1);
        System.out.println(mySingleList.isPalindrome());

    }

    public static MySingleList mergeSortedLinkedList(MySingleList list1,MySingleList list2){
        //边界条件
        if(list1 == null){
            return list2;
        }
        if(list2 == null){
            return list1;
        }
        MySingleList.ListNode cur1 = list1.head;
        MySingleList.ListNode cur2 = list2.head;
        MySingleList mySingleList = new MySingleList();
        MySingleList.ListNode tmp = null;
        if(cur1.val <= cur2.val){
            tmp = cur1;
            cur1 = cur1.next;
        }else{
            tmp = cur2;
            cur2 = cur2.next;
        }
        MySingleList.ListNode head = tmp;
        while(cur1 != null && cur2 != null){
            if(cur1.val <= cur2.val){
                tmp.next = cur1;
                cur1 = cur1.next;
                tmp = tmp.next;
            }else{
                tmp.next = cur2;
                cur2 = cur2.next;
                tmp = tmp.next;
            }
        }
        if(cur1 == null){
            tmp.next = cur2;
        }
        if(cur2 == null){
            tmp.next = cur1;
        }
        mySingleList.head = head;
        return mySingleList;
    }
}
